package zwo.service.impl;


import zwo.dao.ProductMapper;
import zwo.model.Product;
import zwo.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ProductServiceImpl implements ProductService {

    @Autowired
    private ProductMapper productMapper;

    public Integer productEdit(Product product) {
        if (productMapper.productEditIsName(product) == 0) {
            return productMapper.productEdit(product);
        } else {
            return 0;
        }
    }

    public Integer productDelete(Product product) {
        if (productMapper.productisPutOnSale(product) == 0) {
            return 0;
        } else {
            return productMapper.productDelete(product);
        }
    }

    public Integer productAdd(Product product) {
        if (productMapper.productEditIsName(product) == 0) {
            return productMapper.productAdd(product);
        } else {
            return 0;
        }
    }

    public Integer productEditisPutOnSales(Product product) {
        if (productMapper.productIsPutOnSales(product) == 0) {
            return productMapper.productEditisPutOnSales(product);
        } else {
            return 0;
        }
    }

    public Integer productEditisToday(Product product) {

        if (product.getIsToday() != true) {
            return productMapper.productEditisToday(product);
        } else if (productMapper.productIsTodayNumber(product) >= 8) {
            return 0;
        } else {
            return productMapper.productEditisToday(product);
        }
    }
}
